package com.zxlspace.java8;

/**
 * @ClassName Java8Tester
 * @Description TODO
 * @Author zhangxiaolin@pinpianyi.com
 * @Date 2019/4/11 14:18
 * @Version 1.0
 **/
public class Java8Tester {
    public static void main(String[] args) {
        Java8Tester tester = new Java8Tester();

        //类型申明
        MathOperation addition = (int a, int b) -> a + b;

        //不申明类型
        MathOperation subtraction = (a,b) -> a - b;

        //大括号中的返回语句
        MathOperation multiplication = (int a, int b) -> {return  a * b; };

        //没有大括号即返回语句
        MathOperation division = (int a, int b) -> a / b;
        System.out.println("10 + 5 = "+  tester.operate(10,5, addition));
        System.out.println("10 - 5 = "+  tester.operate(10,5, subtraction));
        System.out.println("10 x 5 = "+  tester.operate(10,5, multiplication));
        System.out.println("10 / 5 = "+  tester.operate(10,5, division));

        //不用括号
        GreetingService service1 = message -> System.out.println("Hello " + message);

        //用括号
        GreetingService service2 = (message) -> System.out.println("Hello " + message);
        service1.sayMessage("Google");
        service2.sayMessage("Baidu");
    }

    interface MathOperation{
        int operation(int a, int b);
    }

    interface GreetingService{
        void sayMessage(String message);
    }

    private int operate(int a, int b, MathOperation mathOperation) {
        return mathOperation.operation(a, b);
    }
}


